using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Home.Controls
{
    public class TreeListViewTemplate : Control, IDataItemContainer
    {
        private int m_DataItemIndex;
        private int m_DisplayIndex;

        public TreeListViewTemplate()
        {

        }
        public TreeListViewTemplate(object obj, int index)
        {
            this.DataItem = obj;
            m_DataItemIndex = m_DisplayIndex = index;
        }

        private int m_Depth;
        public virtual int Depth
        {
            get
            {
                return m_Depth;
            }
            set
            {
                m_Depth = value;
            }
        }

        private string m_Children;
        public virtual string Children
        {
            get
            {
                return m_Children;
            }
            set
            {
                m_Children = value;
            }
        }

        /// <summary>
        /// TreeListNode Object
        /// </summary>
        public TreeListNode Node
        {
            get
            {
                if (dataItem==null)
                {
                    return null;
                }
                return (TreeListNode)dataItem;
            }
        }

        /// <summary>
        /// Text Property of TreeListNode
        /// </summary>
        public string NodeText
        {
            get
            {
                if (Node == null)
                {
                    return string.Empty;
                }
                return Node.Text;
            }
        }

        /// <summary>
        /// NodeTreeTr Property of TreeListNode
        /// </summary>
        public string NodeTreeTr
        {
            get
            {
                if (Node == null)
                {
                    return string.Empty;
                }
                return Node.TreeTr;
            }
        }

        /// <summary>
        /// NodeTreeImage(html code of tree line and image ) Property of TreeListNode
        /// </summary>
        public string NodeTreeImage
        {
            get
            {
                if (Node == null)
                {
                    return string.Empty;
                }
                return Node.TreeImage;
            }
        }

        /// <summary>
        /// TreeListNode.TreeListNodeData
        /// </summary>
        internal TreeListNodeData NodeData
        {
            get
            {
                if (Node==null)
                {
                    return new TreeListNodeData();
                }
                return Node.Data;
            }
        }

        /// <summary>
        /// Get TreeListNodeData's Value; TreeListNode.TreeListNodeData.Value(string strKey)
        /// </summary>
        /// <param name="strKey">key</param>
        /// <returns>value</returns>
        public string GetNodeValue(string strKey)
        {
            return NodeData.GetValue(strKey);
        }

        #region IDataItemContainer Members

        private object dataItem;
        public object DataItem
        {
            get
            {
                return this.dataItem;
            }
            set
            {
                this.dataItem = value;
            }
        }

        public int DataItemIndex
        {
            get { return m_DataItemIndex; }
        }

        public int DisplayIndex
        {
            get { return m_DisplayIndex; }
        }

        #endregion
    }
}
